package com.nwpu.coursesupport.service.imple;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nwpu.coursesupport.entity.bean.JSONResult;
import com.nwpu.coursesupport.enumeration.Status;
import com.nwpu.coursesupport.enumeration.TaskType;
import com.nwpu.coursesupport.service.AbstractService;
import com.nwpu.coursesupport.service.param.IDParam;
import com.nwpu.coursesupport.tool.ServiceUtil;
import com.nwpu.coursesupport.view.LessonTaskInLessonDetailView;
import com.nwpu.coursesupport.view.mapper.LessonTaskInLessonDetailViewMapper;

@Service
public class LessonTaskInLessonDetailViewService extends AbstractService{

	@Autowired
	private LessonTaskInLessonDetailViewMapper lessonTaskInLessonDetailViewMapper;
	
    protected static Logger logger = LoggerFactory.getLogger(LessonTaskInLessonDetailViewService.class);

	
	public JSONResult teacherDetailView(IDParam p){
		JSONResult rst=new JSONResult();
		rst.fail();
		
		if(p==null||p.getId()<=0){
			return rst.fail("参数有误");
		}
		
		LessonTaskInLessonDetailView view=this.lessonTaskInLessonDetailViewMapper.teacherDetail(p.getId());
		
		if(view==null){
			logger.error("该分配记录不存在");
			return rst.fail("该分配记录不存在");
		}
		
		
		view.setAttachment(ServiceUtil.DeserializeFiles(view.getAttachmentBytes()));
		view.setAnswerAttachment(ServiceUtil.DeserializeFiles(view.getAnswerAttachmentBytes()));
		rst.addData("view", view);
		rst.addData("type", TaskType.ASKINLESSON);
		rst.success();
		return rst;
	}
}
